package bman.game.battletank;

import static bman.game.battletank.BattleTank.EAST;
import static bman.game.battletank.BattleTank.NORTH;
import static bman.game.battletank.BattleTank.SOUTH;
import static bman.game.battletank.BattleTank.WEST;
import static bman.game.battletank.BattleTank.padding;

import java.util.logging.Logger;

import bman.game.battletank.BattleTank.Types;
import bman.game.engine.Entity;
import bman.game.engine.GameMap;
import bman.game.engine.GraphicsEngine;
import bman.game.engine.Timer;

public class ExplosionAntimator extends Thread
{
	Logger log = Logger.getLogger(this.getClass().getName());
	
	GameMap map = null;
	Entity e;
	public ExplosionAntimator(GameMap map, Entity entity)
	{
		this.map = map;
		
		int xplodeX = 0;
		int xplodeY = 0;
		
		if(NORTH.equalsIgnoreCase(entity.getBearing()))
		{
			xplodeX = entity.x();
			xplodeY = entity.y() - padding;
		}
		else if(SOUTH.equalsIgnoreCase(entity.getBearing()))
		{
			xplodeX = entity.x();
			xplodeY = entity.y() + padding;
		}
		else if(EAST.equalsIgnoreCase(entity.getBearing()))
		{
			xplodeX = entity.x() + padding;
			xplodeY = entity.y();
		}
		else if(WEST.equalsIgnoreCase(entity.getBearing()))
		{
			xplodeX = entity.x() - padding;
			xplodeY = entity.y();
		}

		e = map.addEntity(Types.EXPLOSION,xplodeX,xplodeY,10);
		log.info("Explosion created. ID is: "+e.getID());
		
		start();
	}
	
	public void run()
	{
		try
		{
			Timer t = GraphicsEngine.getTimer();
			sleep(t.getSleep()*5);
		}
		catch(Exception e)
		{
			
		}

		map.remove(e);
	}
}
